<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="1000px" append-to-body custom-class="import-dialog">
      <el-table v-loading="loading" :data="list">
        <!-- <el-table-column type="selection" width="50" align="center" /> -->
        <el-table-column label="单号" align="center" key="houseInspectionId" prop="houseInspectionId"
          :show-overflow-tooltip="true" />
        <el-table-column label="房间" align="center" key="fullAddress" prop="fullAddress" width="120" />
        <el-table-column label="分类" align="center" key="inspectionType" prop="inspectionType" width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.inspection_type" :value="scope.row.inspectionType"/>
          </template>
        </el-table-column>
        <el-table-column label="预计开始时间" align="center" prop="scheduledTime" width="160">
          <template slot-scope="scope">
            <span>{{ scope.row.scheduledTime | formatDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="inspectionState">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.inspection_state" :value="scope.row.inspectionState"/>
          </template>
        </el-table-column>
        <el-table-column label="结果" align="center" key="inspectionResult" prop="inspectionResult" width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.inspection_result" :value="scope.row.inspectionResult"/>
          </template>
        </el-table-column>
        <el-table-column label="验房员" align="center" key="homeInspectorName" prop="homeInspectorName" width="120" />
        <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-info" @click="handleDetail(scope.row)"
              v-hasPermi="['enterprise:inspection:query']">详情</el-button>
            <!-- <el-button size="mini" type="text" icon="el-icon-user" @click="handleAssign(scope.row)"
              v-hasPermi="['enterprise:inspection:edit']" v-if="scope.row.inspectionState == 1">指派人员</el-button>
            <el-button size="mini" type="text" icon="el-icon-user" @click="handleReplace(scope.row)"
              v-hasPermi="['enterprise:inspection:change']" v-if="scope.row.inspectionState == 2">更换人员</el-button> -->
            <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['enterprise:inspection:remove']">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
      <detail v-model="detailVisible" :data="houseInspection" />
      <!-- <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">保 存</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import { debounce } from "@/utils";
import { listInspection } from '@/api/houseCleaning/inspection';
import detail from './detail.vue';
export default {
  dicts: ['inspection_state', 'inspection_result', 'inspection_type'],
  components: {
    detail
  },
  props: {
    title: {
      default: "验房信息",
    },
    value: {
      default: false,
    },
    data: {
      default: undefined,
    },
    orderId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      visible: false,
      form: {},
      rules: {
      },
      orderInfo: {},
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      //列表
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: undefined,
        fullAddress: undefined,
        inspectionType: undefined,
        inspectionState: undefined,
        homeInspectorName: undefined,
        houseInspectionId: undefined
      },
      //验房分类列表
      inspectionTypeList: [
        { label: '日常检查', value: 1 },
        { label: '换退验房', value: 2 },
      ],
      //状态列表
      inspectionStateList: [
        { label: '待指派', value: 1 },
        { label: '已指派', value: 2 },
        { label: '已完成', value: 3 },
      ],
      inspectionResultList: [
        { label: '正常', value: 1 },
        { label: '损坏', value: 2 },
      ],
      detailVisible: false,
      houseInspection: {}
    };
  },
  computed: {
  },
  watch: {
    value(newVal, oldVal) {
      if (newVal) {
        this.init();
      }
      this.visible = newVal; // 监测value的变化，并赋值。
    },
    visible(val) {
      this.$emit("input", val); // 此处监测visible目的为关闭弹窗时，重新更换value值，注意emit的事件一定要为input。
    },
  },
  methods: {
    init() {
      this.reset()
      this.getList()
    },
    reset() {
      this.form = {
        houseState: '1'
      }
      this.resetForm("form");
      for (const key in this.data) {
        if (Object.hasOwnProperty.call(this.data, key)) {
          this.form[key] = this.data[key];
        }
      }

    },
    getList() {
      this.loading = true;
      this.queryParams.orderId = this.orderId
      listInspection(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    // 详情
    handleDetail(row) {
      this.houseInspection = { ...row }
      this.detailVisible = true
    },
    submitForm: debounce(function () {
      this.$refs['form'].validate(valid => {
        if (valid) {
          // if (this.form.cleanerId) {
          //   editCleaner(this.form).then(response => {
          //     if (response.code == 200) {
          //       this.$emit("success");
          //       this.$message.success(response.msg);
          //       this.visible = false;
          //     } else {
          //       this.$message.error(response.msg);
          //     }
          //   })
          // } else {
          //   addCleaner(this.form).then(response => {
          //     if (response.code == 200) {
          //       this.$emit("success");
          //       this.$message.success(response.msg);
          //       this.visible = false;
          //     } else {
          //       this.$message.error(response.msg);
          //     }
          //   })
          // }
        }
      })
    }, 500),
    cancel() {
      this.reset();
      this.visible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/dialog.scss";
</style>
